Git-ல் Merging என்றால் என்ன?
Git-ல் merging என்பது ஒரு கிளையிலிருந்து மாற்றங்களை மற்றொரு கிளையில் இணைப்பதாகும்.
வெவ்வேறு அம்சங்கள் அல்லது பிழை திருத்தங்களில் தனித்தனியாக வேலை செய்த பிறகு உங்கள் வேலையை ஒன்றாகக் கொண்டு வருவதற்கான வழியிது.
பொதுவான git merge விருப்பங்கள்
git merge
ஒரு கிளையை உங்கள் தற்போதைய கிளையில் இணைக்கவும்
git merge --no-ff
எப்போதும் ஒரு merge commit உருவாக்கவும்
git merge --squash
மாற்றங்களை ஒரு commit-ல் இணைக்கவும்
git merge --abort
நடந்து கொண்டிருக்கும் merge-ஐ கைவிடவும்
கிளைகளை இணைத்தல் (git merge)
ஒரு கிளையிலிருந்து மாற்றங்களை மற்றொரு கிளையில் இணைக்க, git merge பயன்படுத்தவும்.
பொதுவாக, நீங்கள் முதலில் இணைக்க விரும்பும் கிளைக்கு மாறவும் (பொதுவாக main அல்லது master), பின்னர் இணைக்க விரும்பும் கிளைப் பெயருடன் merge கட்டளையை இயக்கவும்.
எடுத்துக்காட்டு
git checkout master
Switched to branch 'master'
git merge emergency-fix
Updating 09f4acd..dfa79db
Fast-forward
index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
emergency-fix கிளை நேரடியாக master-லிருந்து வந்தது, மேலும் நாங்கள் வேலை செய்தபோது master-ல் வேறு எந்த மாற்றங்களும் செய்யப்படவில்லை, எனவே Git இதை master-ன் தொடர்ச்சியாகக் காண்கிறது.
எனவே அது "Fast-forward" செய்ய முடியும், master மற்றும் emergency-fix இரண்டையும் ஒரே commit-க்கு சுட்டிக்காட்டுகிறது.
கிளைகளை இணைப்பதற்கான சிறந்த நடைமுறைகள்
சிறந்த நடைமுறைகள்:
- merge தொடங்குவதற்கு முன் எப்போதும் உங்கள் மாற்றங்களை commit அல்லது stash செய்யவும்
- மோதல்களைக் குறைக்க உங்கள் அம்சக் கிளையில் முக்கிய கிளையிலிருந்து தவறாமல் merge செய்யவும்
- மோதல்களை கவனமாகப் படித்து தீர்க்கவும்—கண்மூடித்தனமாக அனைத்து மாற்றங்களையும் ஏற்க வேண்டாம்
- தெளிவான மற்றும் விளக்கமான merge commit செய்திகளை எழுதவும்
நடைமுறை எடுத்துக்காட்டுகள்
Merge-ஐ கைவிடு
git merge --abort
Merge-ன் போது நிலையைப் பார்
git status
மோதலைத் தீர்த்து merge-ஐ முடிக்க
மோதல் கோப்பைத் திருத்தவும், பின்னர் git add மற்றும் git commit
Fast-forward merge
புதிய commits வேறுபடாதபோது நடக்கும்—Git கிளை சுட்டியை முன்னோக்கி நகர்த்தும்
No-fast-forward merge
கிளை வரலாற்றைப் பாதுகாக்க git merge --no-ff branch பயன்படுத்தவும்
எடுத்துக்காட்டு: கிளையை நீக்குதல்
git branch -d emergency-fix
Deleted branch emergency-fix (was dfa79db)
Non-Fast-Forward Merge (git merge --no-ff)
இயல்பாக, உங்கள் கிளையை fast-forward-உடன் இணைக்க முடிந்தால் (அடிப்படையில் புதிய commits இல்லை), Git கிளை சுட்டியை முன்னோக்கி நகர்த்தும்.
எப்போதும் ஒரு merge commit உருவாக்க விரும்பினால் (வரலாற்றை தெளிவாக வைத்திருக்க), git merge --no-ff branchname பயன்படுத்தவும்.
எடுத்துக்காட்டு
git merge --no-ff feature-branch
Merge made by the 'recursive' strategy.
index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Squash Merge (git merge --squash)
ஒரு கிளையிலிருந்து அனைத்து மாற்றங்களையும் ஒரு commit-ல் இணைக்க விரும்பினால் (ஒவ்வொரு commit-உம் வைத்திருப்பதற்குப் பதிலாக), git merge --squash branchname பயன்படுத்தவும்.
இணைப்பதற்கு முன் commit வரலாற்றை சுத்தம் செய்வதற்கு இது பயனுள்ளதாக இருக்கும்.
எடுத்துக்காட்டு
git merge --squash feature-branch
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
Merge-ஐ கைவிடுதல் (git merge --abort)
Merge-ன் போது சிக்கல் ஏற்பட்டால் (தீர்க்க விரும்பாத மோதல் போன்றவை), நீங்கள் git merge --abort-உடன் merge-ஐ ரத்து செய்து முன்பு இருந்தது போல் திரும்பலாம்.
எடுத்துக்காட்டு
git merge --abort
Merge Conflict என்றால் என்ன?
இரண்டு கிளைகளில் உள்ள மாற்றங்கள் ஒரு கோப்பின் ஒரே பகுதியைத் தொடும் போது, எந்தப் பதிப்பை வைத்திருக்க வேண்டும் என Git-க்குத் தெரியாதபோது ஒரு merge conflict ஏற்படுகிறது.
இது இரண்டு பேர் ஒரு ஆவணத்தில் ஒரே வாக்கியத்தை வெவ்வேறு வழிகளில் திருத்துவது போன்றது—எந்தப் பதிப்பைப் பயன்படுத்துவது என்பதைத் தீர்மானிக்க Git-க்கு உங்கள் உதவி தேவை.
Merge Conflict-ஐ எவ்வாறு தீர்ப்பது
Git உங்கள் கோப்பில் மோதலைக் குறிக்கும்.
நீங்கள் கோப்பைத் திறக்க வேண்டும், <<<<<<< HEAD மற்றும் ======= போன்ற வரிகளைத் தேடி, இறுதிப் பதிப்பு என்னவாக இருக்க வேண்டும் என முடிவு செய்ய வேண்டும்.
பின்னர், உங்கள் மாற்றங்களை stage மற்றும் commit செய்யவும்.
சிக்கல் தீர்வு & உதவிக்குறிப்புகள்
⚠️ முக்கியமான உதவிக்குறிப்புகள்:
- Merge-ஐ கைவிட விரும்பினால், git merge --abort பயன்படுத்தவும்
- Merge தொடங்குவதற்கு முன் எப்போதும் உங்கள் மாற்றங்களை commit அல்லது stash செய்யவும்
- மோதல் குறிப்பான்களை கவனமாகப் படித்து, சிக்கலைத் தீர்த்த பிறகு அவற்றை அகற்றவும்
- உங்கள் கவனத்தை எந்தக் கோப்புகள் தேவைப்படுகின்றன என்பதைப் பார்க்க git status பயன்படுத்தவும்
- உறுதியாக இல்லாவிட்டால், ஒரு குழு உறுப்பினரைக் கேளுங்கள் அல்லது பிழைச் செய்தியைத் தேடுங்கள்
Merge Conflict எடுத்துக்காட்டு
கடந்த அத்தியாயத்திலிருந்து hello-world-images-க்கு நகர்ந்து, தொடர்ந்து வேலை செய்யலாம்.
கிளை மாற்றம் மற்றும் கோப்பு மாற்றம்
git checkout hello-world-images
Switched to branch 'hello-world-images'
cat index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>
<h1>Hello world!</h1>
<div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div>
<p>This is the first file in my new Git Repo.</p>
<p>A new line in our file!</p>
<div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div>
</body>
</html>
இப்போது, நாங்கள் இங்கே எங்கள் வேலையை முடித்துவிட்டோம் மற்றும் இந்தக் கிளைக்கு stage மற்றும் commit செய்யலாம்:
Commit செய்தல்
git add --all
git commit -m "added new image"
[hello-world-images 1f1584e] added new image
2 files changed, 1 insertion(+)
create mode 100644 img_hello_git.jpg
index.html இரண்டு கிளைகளிலும் மாற்றப்பட்டுள்ளது என்பதை நாம் காண்கிறோம்.
இப்போது நாம் hello-world-images-ஐ master-ல் இணைக்கத் தயாராக உள்ளோம்.
ஆனால் நாம் சமீபத்தில் master-ல் செய்த மாற்றங்களுக்கு என்ன நடக்கும்?
Merge முயற்சி
git checkout master
git merge hello-world-images
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
index.html-க்கான பதிப்புகளுக்கு இடையே மோதல் இருப்பதால் merge தோல்வியடைந்தது.
நிலையைப் பார்ப்போம்:
நிலை சரிபார்த்தல்
git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Changes to be committed:
new file: img_hello_git.jpg
new file: img_hello_world.jpg
Unmerged paths:
(use "git add ..." to mark resolution)
both modified: index.html
இது index.html-ல் ஒரு மோதல் உள்ளது என உறுதிப்படுத்துகிறது, ஆனால் பட கோப்புகள் commit செய்யத் தயாராக உள்ளன.
எனவே நாம் அந்த மோதலை சரிசெய்ய வேண்டும். எங்கள் எடிட்டரில் கோப்பைத் திறக்கவும்:
மோதல் கோப்பு
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>
<h1>Hello world!</h1>
<div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div>
<p>This is the first file in my new Git Repo.</p>
<<<<<<< HEAD
<p>This line is here to show how merging works.</p>
=======
<p>A new line in our file!</p>
<div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div>
>>>>>>> hello-world-images
</body>
</html>
பதிப்புகளுக்கு இடையே உள்ள வேறுபாடுகளை நாம் காணலாம் மற்றும் நமக்கு வேண்டியவாறு திருத்தலாம்:
தீர்க்கப்பட்ட கோப்பு
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>
<h1>Hello world!</h1>
<div><img src="img_hello_world.jpg" alt="Hello World from Space" style="width:100%;max-width:960px"></div>
<p>This is the first file in my new Git Repo.</p>
<p>This line is here to show how merging works.</p>
<div><img src="img_hello_git.jpg" alt="Hello Git" style="width:100%;max-width:640px"></div>
</body>
</html>
இப்போது நாம் index.html-ஐ stage செய்து நிலையைச் சரிபார்க்கலாம்:
மோதலைத் தீர்த்தல்
git add index.html
git status
On branch master
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
new file: img_hello_git.jpg
new file: img_hello_world.jpg
modified: index.html
மோதல் சரிசெய்யப்பட்டது, மேலும் merge-ஐ முடிக்க commit பயன்படுத்தலாம்:
Merge-ஐ முடித்தல்
git commit -m "merged with hello-world-images after fixing conflicts"
[master e0b6038] merged with hello-world-images after fixing conflicts
மேலும் hello-world-images கிளையை நீக்கவும்:
கிளையை நீக்குதல்
git branch -d hello-world-images
Deleted branch hello-world-images (was 1f1584e)
வாழ்த்துக்கள்!
இப்போது கிளைகள் மற்றும் merging எவ்வாறு செயல்படுகிறது என்பதைப் பற்றி நீங்கள் நன்றாகப் புரிந்து கொண்டீர்கள்.
தொலை களஞ்சியத்துடன் வேலை செய்யத் தொடங்குவதற்கான நேரம்!